package com.bing.controller.admin;

import com.bing.bean.TestTable;
import com.bing.bean.ZTree;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Created by Administrator on 2016/11/20.
 */

@Controller
@RequestMapping(Json.PRE)
public class Json {
    public static final String PRE = "admin/json";
    public static final Logger LOGGER = LoggerFactory.getLogger(Login.class);


    @RequestMapping(value = "datagrid-test.json", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public List<TestTable> datagrid() {
        LOGGER.info("请求json:{}");
        List<TestTable> testTable = new ArrayList<>();
        testTable.add(new TestTable("bingo","true", 18,"看书","english", "haha zhu", new Date(),"上海市",true));
        testTable.add(new TestTable("kaibing", "false", 28,"动漫","china", "haha nv", new Date(),"金溪",false));
        return testTable;
    }


    @RequestMapping(value = "tags.json", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public List<String> tags() {
        LOGGER.info("请求tags:{}");
        List<String> tags=new ArrayList<>();
        tags.add("abc");
        tags.add("bingo");
        tags.add("china");
        tags.add("english");
        tags.add("shuxue");
        tags.add("yuwen");
        tags.add("wuli");
        return tags;
    }

    @RequestMapping(value = "{name}.json", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public List<ZTree> login(@PathVariable String name) {
        LOGGER.info("请求json:{}", name);
        return menu();
    }

    private List<ZTree> menu() {
        List<ZTree> menu = new ArrayList<>();
        ZTree zTree = new ZTree("表单相关");
        zTree.addChild("base-button", "按钮", "navtab", "test/form.html");
        zTree.addChild("input-button", "文本框", "navtab", "html/input.button");
        menu.add(zTree);
        zTree = new ZTree("综合应用");
        zTree.addChild("base-demo-form", "示例2", "navtab", "html/demo.button");
        menu.add(zTree);
        return menu;
    }
}
